﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace eTerm.Platform.Web
{
    public abstract class BaseEntityUserControl<T>:BaseUserControl where T:new()
    {
        public string EntityIdentity
        {
            get {
                if (ViewState["EntityKey"] == null)
                    return string.Empty;
                else
                    return ViewState["EntityKey"].ToString();
            }
            set {
                ViewState["EntityKey"] = value;
            }
        }

        protected virtual T GetEntityFromDb() {
            return new T();
        }

        protected virtual T GetEntityFromControl() {
            return new T();
        }

        protected virtual void SaveEntity(T model) { 
            
        }

        public T Save() {
            T model = GetEntityFromControl();
            SaveEntity(model);
            return model;
        }

    }
}
